<?php if(!class_exists("View", false)) exit("no direct access allowed");?><main id="main" class="in">
    <div class="container-fluid">
        <div class="row">
            <div class="col-xs-12">
                <div class="panel">
                    <div class="panel-heading">
                        <div class="title">  
                          浏览应用
                          <div class="pull-right">
                            <a style="display:inline;" href="#" class="btn btn-primary appadd" data-width="550"><i class="icon-plus"></i> 新增应用</a>
                          </div>
                        </div>
                        
                    </div>
                    <div class="panel-body">  
                      <table class="table datatable applist">
                        <thead>
                          <tr>
                            <th>ID</th>
                            <th>应用名称</th>
                            <th>应用图标</th>
                            <th>应用描述</th>
                            <th>应用地址</th>
                            <th>参数</th>
                            <th>状态</th>
                            <th>操作</th>
                          </tr>
                        </thead>
                        <tbody>
                          <?php if(!empty($apps['data'])){ $_foreach_v_counter = 0; $_foreach_v_total = count($apps['data']);?><?php foreach( $apps['data'] as $k => $v ) : ?><?php $_foreach_v_index = $_foreach_v_counter;$_foreach_v_iteration = $_foreach_v_counter + 1;$_foreach_v_first = ($_foreach_v_counter == 0);$_foreach_v_last = ($_foreach_v_counter == $_foreach_v_total - 1);$_foreach_v_counter++;?>
                          <tr>
                            <td><?php echo htmlspecialchars($v['id'], ENT_QUOTES, "UTF-8"); ?></td>
                            <td><?php echo htmlspecialchars($v['appName'], ENT_QUOTES, "UTF-8"); ?></td>
                            <td>
                                <img src="<?php echo htmlspecialchars($v['appImg'], ENT_QUOTES, "UTF-8"); ?>" width="80px" height="80px" class="img-rounded" alt="<?php echo htmlspecialchars($v['appName'], ENT_QUOTES, "UTF-8"); ?>">
                            </td>
                            <td><?php echo htmlspecialchars($v['appDesc'], ENT_QUOTES, "UTF-8"); ?></td>
                            <td><?php echo htmlspecialchars($v['appUrl'], ENT_QUOTES, "UTF-8"); ?></td>
                            <td><?php echo htmlspecialchars($v['appParams'], ENT_QUOTES, "UTF-8"); ?></td>
                            <td>
                                <?php if ($v['appStatus'] == 1) : ?>
                                <p class="text-green">正常</p>
                                <?php else : ?>
                                <p class="text-red">下线</p>
                                <?php endif; ?>
                            </td>
                            <td>                              
                              <a href="<?php echo url(array('c'=>"System", 'a'=>"AppsPrivIndex", 'id'=>"", ));?><?php echo htmlspecialchars($v['id'], ENT_QUOTES, "UTF-8"); ?>" title="配置权限模块" class="with-padding"><i class="icon-common-lock icon-lock"></i></a>
                              <a href="#" onclick="del(<?php echo htmlspecialchars($v['id'], ENT_QUOTES, "UTF-8"); ?>)" title="删除应用" class="with-padding"><i class="icon-common-trash icon-trash"></i></a>
                            </td>
                          </tr>
                          <?php endforeach; }?>
                        </tbody>
                      </table>
                      <?php if ($apps['pager']) : ?>
                      <ul id="myPager" class="pager" data-ride="pager" data-link-Creator="?page={page}" data-page="<?php echo htmlspecialchars($apps['pager']['current_page'], ENT_QUOTES, "UTF-8"); ?>" data-rec-total="<?php echo htmlspecialchars($apps['pager']['total_count'], ENT_QUOTES, "UTF-8"); ?>" data-max-nav-count="<?php echo htmlspecialchars($apps['pager']['total_page'], ENT_QUOTES, "UTF-8"); ?>" data-elements="prev_icon,page_of_total_text,next_icon"></ul>                    
                      <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="editModal">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
            <h4 class="modal-title">新增应用</h4>
          </div>
          <div class="modal-body">
            <table align="center" class="table table-borderless"> 
              <tbody><tr>
                <th>应用名称</th>
                <td class="required"><input type="text" name="appName" id="appName" value="" class="form-control" autocomplete="off">
        </td>
              </tr> 
              <tr>
                <th>应用图标</th>
                <td>
                  <img src="../../i/img/bk_cc.png" alt="应用图标" id="tmp_appimg" width="80px" height="80px" class="img-rounded" />
                  <div id="uploader" class="uploader">
                    <div class="file-list" data-drag-placeholder="请拖拽文件到此处"></div>
                    <button type="button" class="btn btn-primary uploader-btn-browse"><i class="icon icon-cloud-upload"></i> 选择文件</button>
                  </div>
        </td>
              </tr> 
              <tr>
                <th>应用地址</th>
                <td class="required"><input type="text" name="appUrl" id="appUrl" value="" class="form-control" autocomplete="off">
        </td>
              </tr> 
              <tr>
                <th>应用参数</th>
                <td>
                  <textarea name="appParams" id="appParams" rows="5" class="form-control"></textarea>
        </td>
              </tr> 
              <tr>
                <th>应用描述</th>
                <td><textarea name="appDesc" id="appDesc" rows="5" class="form-control"></textarea>
        </td>
              </tr>  
              
            </tbody></table>
          </div>
          <div class="modal-footer">
            <input type="hidden" id="appImg" value="../../i/img/bk_cc.png" />
            <button type="button" class="btn btn-default " data-dismiss="modal">关闭</button>
            <button type="button" class="btn btn-primary appaddbtn">保存</button>
          </div>
        </div>
      </div>
    </div>
    <script src="http://p1.renbenzhihui.com/zui/js/all.js"></script>
          <script src="/i/js/util.js"></script>
          <script src="http://p1.renbenzhihui.com/zui/lib/datatable/zui.datatable.min.js"></script>
          <script src="//p1.renbenzhihui.com/zui/lib/uploader/zui.uploader.min.js"></script>
          <script> 
            function del(id){
                $.get('<?php echo url(array('c'=>"System", 'a'=>"AppDel", 'id'=>"", ));?>'+id,function(data){
                  data = JSON.parse(data);
                    if(data.code/1 == 1){
                      location.reload();
                    }else{
                      new $.zui.Messager(data.msg, {
                                  type: 'danger',
                                  icon: 'exclamation-sign',
                                  placement: 'center' // 定义显示位置
                              }).show();
                    }
                });
            }     
            $(function(){            
              $('.appadd').on('click',function(){
                $('#editModal').modal({
                  name:'editModal',
                  backdrop:true,
                  keyboard:true
                })
              });  
              $('#uploader').uploader({
                  autoUpload: true,            // 当选择文件后立即自动进行上传操作
                  url: '<?php echo url(array('c'=>"FileTool", 'a'=>"UploadFile", ));?>',  // 文件上传提交地址
                  init: {
                      FileUploaded: function (up, file, result) {
                          var return_msg = $.parseJSON(result.response);                          
                          var file_info = return_msg.file_path;
                          $('#appImg').val(file_info);
                          $('#tmp_appimg').attr('src',file_info);
                      }
                  }
              });
              

              $('.appaddbtn').on('click',function(){
                var appName = Utils.paseData($('#appName').val());
                var appDesc = Utils.paseData($('#appDesc').val());
                var appImg = Utils.paseData($('#appImg').val());
                var appUrl = Utils.paseData($('#appUrl').val());
                var appParams = Utils.paseData($('#appParams').val());
                if(appName != ''){
                  $.post('<?php echo url(array('c'=>"System", 'a'=>"AppAdd", ));?>',{appName:appName,appDesc:appDesc,appImg:appImg,appUrl:appUrl,appParams:appParams},function(data){
                    data = JSON.parse(data);
                    if(data.code/1 == 1){
                      location.reload();
                    }else{
                      new $.zui.Messager(data.msg, {
                                  type: 'danger',
                                  icon: 'exclamation-sign',
                                  placement: 'center' // 定义显示位置
                              }).show();
                    }
                  });
                }else{
                  new $.zui.Messager('分组名称为必填项', {
                                  type: 'danger',
                                  icon: 'exclamation-sign',
                                  placement: 'center' // 定义显示位置
                              }).show();
                }
              });
              $('.applist').datatable({
                checkable: true,
                sortable: true,
                minFixedLeftWidth: 300
              });
            });
            </script>
  </main>